//
//  MYGMinTitleCell.swift
//  MYDoctor
//
//  Created by 小火科技 on 2024/4/10.
//

import UIKit

class MYGMinTitleCell: UITableViewCell {

    var model: MYGMicrosrationDyModel? {
        didSet {
            
            guard let item = model else  {
                return
            }
            
            let time = item.updated_at
            var M :Int = 1
            var D :Int = 1
            if let date = time.date(withFormat: "yyyy-MM-dd HH:mm:ss") {
                let calendar = Calendar.current
                let components = calendar.dateComponents([.month], from: date)
                let componentsDay = calendar.dateComponents([.day], from: date)
                if let month = components.month {
                    print("月份是：\(month)")
                    M = month
                }
                if let day = componentsDay.day {
                    print("月份是：\(day)")
                    D = day
                }
            } else {
                print("日期字符串格式不正确")
            }
        
            
            timeLabel.rz.colorfulConfer { confer in
                confer.text("\(D)")?.font(.medium(18)).textColor(.rgba(54, 53, 56, 1))
                confer.text("\(M)月")?.font(.regular(10)).textColor(.rgba(54, 53, 56, 1))
            }
            
            textLab.text = item.content
            
        }
        
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        initUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initUI(){
        contentView.backgroundColor = .rgba(255, 255, 255, 1)
        
        contentView.addSubview(timeLabel)
        contentView.addSubview(bkView)
        bkView.addSubview(textLab)
        bkView.addSubview(icon)
        contentView.addSubview(delButton)
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(22.5)
            make.top.equalTo(14.5)
            make.height.equalTo(25)
        }
        
        delButton.snp.makeConstraints { make in
            make.centerY.equalTo(timeLabel )
            make.right.equalToSuperview().offset(-35)
            make.width.equalTo(30)
        }
        
        bkView.snp.makeConstraints { make in
            make.left.equalTo(75.5)
            make.top.equalTo(timeLabel)
            make.height.equalTo(31)
            make.right.equalTo(delButton.snp.left).offset(-6.5)
        }
        textLab.snp.makeConstraints { make in
            make.left.equalTo(9)
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-31)
        }
        icon.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.width.height.equalTo(15)
            make.right.equalToSuperview().offset(-7.5)
        }
    }
    
    private lazy var timeLabel: UILabel = {
        let label = UILabel()
        label.rz.colorfulConfer { confer in
            confer.text("22")?.font(.medium(18)).textColor(.rgba(54, 53, 56, 1))
            confer.text("8月")?.font(.regular(10)).textColor(.rgba(54, 53, 56, 1))
        }
        return label
    }()
    
    private lazy var bkView:UIView = {
        let bk = UIView()
        bk.backgroundColor = .rgba(246, 246, 246, 1)
        bk.layer.cornerRadius = 1.5
        bk.layer.masksToBounds = true
        return bk
    }()
    
    private lazy var textLab:UILabel = {
        let tw = UILabel()
        tw.text = "文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案"
        tw.textColor = .rgba(44, 44, 44, 1)
        tw.font = .regular(14)
        tw.backgroundColor = .rgba(246, 246, 246, 1)
        tw.lineBreakMode = .byTruncatingTail
        tw.numberOfLines = 1
        return tw
    }()
    
    private lazy var icon:UIImageView = {
        let icon = UIImageView()
        icon.image = UIImage(named: "person")
        return icon
    }()
    
    private lazy var delButton: UIButton = {
        let btn = UIButton()
        btn.setTitle("删除", for: .normal)
        btn.setTitleColor(.rgba(57, 109, 250, 1), for: .normal)
        btn.titleLabel?.font = .regular(11)
        return btn
    }()
    
    
}
